package com.tianquan.server.config;

import java.io.IOException;
import java.util.Properties;

/**
 * @Author: tianquan
 * @CreateTime: 2024-11-03  09:09
 * @Description: 动态配置
 */
public class ServerConfig {

    // 服务器名称
    public static String SERVER_NAME;
    // 版本号
    public static String SERVER_VERSION;
    // 端口号
    public static Integer SERVER_PORT;
    // 用户名
    public static String USER;
    // 密码
    public static String PASSWORD;

    static {
        Properties properties = new Properties();
        try {
            properties.load(ServerConfig.class.getClassLoader().getResourceAsStream("server.properties"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        SERVER_NAME = properties.get("server.name").toString();
        SERVER_VERSION = properties.get("server.version").toString();
        SERVER_PORT = Integer.valueOf(properties.get("server.port").toString());
        USER = properties.get("server.user").toString();
        PASSWORD = properties.get("server.password").toString();
    }

    // 验证用户名密码
    public static boolean login(String user, String password) {
        return USER.equals(user) && PASSWORD.equals(password);
    }

    // 打印图标
    public static void printIcon() {
        System.out.println("\n" +
                "______ ______                _    \n" +
                "| ___ \\| ___ \\              | |   \n" +
                "| |_/ /| |_/ /  __ _  _ __  | | __\n" +
                "|  __/ | ___ \\ / _` || '_ \\ | |/ /\n" +
                "| |    | |_/ /| (_| || | | ||   < \n" +
                "\\_|    \\____/  \\__,_||_| |_||_|\\_\\\n" +
                "                             "  + SERVER_VERSION);
    }

}
